package day03;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.List;

public class Demo01 {
    public static void main(String[] args) {
        List<String> list = (List) Proxy.newProxyInstance(
                DemoHandler.class.getClassLoader(),
                new Class[]{List.class},
                new DemoHandler()
        );
        System.out.println(list.getClass());
        list.add("Tom");
        list.add("Jerry");
        list.add("Andy");
        list.clear();
        //String str = list.get(2);
        //System.out.println(str);
    }
}
class DemoHandler implements InvocationHandler{
    @Override
    public Object invoke(
            Object proxy,
            Method method,
            Object[] args) throws Throwable {
        System.out.println("DemoHandler.invoke");
        System.out.println(proxy.getClass());
        System.out.println(method);
        System.out.println(Arrays.toString(args));
        return false;
    }
}
